//
//  StoreDetailsTopView.m
//  aMoment
//
//  Created by dllo on 15/10/4.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "StoreDetailsTopView.h"
#import "AllHeaderFiles.h"

@implementation StoreDetailsTopView

- (void)dealloc
{
    [_groupLabel release];
    [_titleLabel release];
    [_userImageView release];
    [_usernameLabel release];
    [_addTimeLabel release];
    [_postsInfoDict release];
    [_lineLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    self.groupLabel = [[UILabel alloc] init];
    _groupLabel.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    [self addSubview:_groupLabel];
    [_groupLabel release];
    
    self.titleLabel = [[UILabel alloc] init];
    _titleLabel.numberOfLines = 0;
    _titleLabel.font = [UIFont fontWithName:@"Helvetica" size:17];
    [self addSubview:_titleLabel];
    [_titleLabel release];
    
    self.userImageView = [[UIImageView alloc] init];
    _userImageView.contentMode = UIViewContentModeScaleAspectFill;
    _userImageView.clipsToBounds = YES;
    [self addSubview:_userImageView];
    [_userImageView release];
    
    self.usernameLabel = [[UILabel alloc] init];
    _usernameLabel.font = [UIFont systemFontOfSize:FONTSIZE_MIDDLE];
    [self addSubview:_usernameLabel];
    [_usernameLabel release];
    
    self.addTimeLabel = [[UILabel alloc] init];
    _addTimeLabel.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    _addTimeLabel.textColor = FONTCOLOR_GRAY;
    _addTimeLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_addTimeLabel];
    [_addTimeLabel release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _groupLabel.frame = CGRectMake(20 * FIT_WIDTH, 15 * FIT_HEIGHT, self.Width - 40 * FIT_WIDTH, 20 * FIT_HEIGHT);
    _titleLabel.frame = CGRectMake(_groupLabel.X, _groupLabel.Y + _groupLabel.Height + 5 * FIT_HEIGHT, _groupLabel.Width, 60 * FIT_HEIGHT);
    
    _userImageView.frame = CGRectMake(_titleLabel.X, _titleLabel.Y + _titleLabel.Height, 32 * FIT_WIDTH, 32 * FIT_WIDTH);
    _userImageView.layer.cornerRadius = _userImageView.Width / 2;
    
    _addTimeLabel.frame = CGRectMake(self.Width - _userImageView.X - 150 * FIT_WIDTH, _userImageView.Y + 6 * FIT_WIDTH, 150 * FIT_WIDTH, _groupLabel.Height);
    _usernameLabel.frame = CGRectMake(_userImageView.X + _userImageView.Width + 5 * FIT_WIDTH, _addTimeLabel.Y, self.Width - 40 * FIT_WIDTH - _userImageView.Width - 5 * FIT_WIDTH - _addTimeLabel.Width, _groupLabel.Height);
    
    self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(_groupLabel.X, _userImageView.Y + _userImageView.Height + 15, _groupLabel.Width, 1)];
    [self addSubview:_lineLabel];
    [_lineLabel release];
}

#pragma mark 重写set方法
- (void)setPostsInfoDict:(NSDictionary *)postsInfoDict
{
    if (_postsInfoDict != postsInfoDict) {
        [_postsInfoDict release];
        _postsInfoDict = [postsInfoDict retain];
    }
    _groupLabel.text = [NSString stringWithFormat:@"from: %@", [[_postsInfoDict objectForKey:@"groupInfo"] objectForKey:@"title"]];
    _titleLabel.text = [_postsInfoDict objectForKey:@"title"];
//    [_userImageView setImageWithURL:[NSURL URLWithString:[[_postsInfoDict objectForKey:@"userinfo"] objectForKey:@"icon"]]];
    [_userImageView setImageWithURL:[NSURL URLWithString:[[_postsInfoDict objectForKey:@"userinfo"] objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"iconfont-head@2x"]];
    _usernameLabel.text = [[_postsInfoDict objectForKey:@"userinfo"] objectForKey:@"uname"];
    _addTimeLabel.text = [_postsInfoDict objectForKey:@"addtime_f"];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
